<?php
declare (strict_types=1);

namespace app\common\model;

use think\facade\Event;

class Answer extends Base
{
    protected $name = 'answer';


    public function user()
    {
        return $this->hasOne(User::class, 'id', 'uid')->field('id,code,nickname,mobile');
    }

    public function getStatusAttr($value)
    {
        switch ($value) {
            case 1:
                return '未回复';
            case 2:
                return '已回复';
            default:
                return '未查看';
        }
    }


    public static function add($param, $user): array
    {
        try {

            $info = parent::create([
                'uid' => $user->id,
                'code' => $user->code,
                'comment' => $param['comment'],
                'type' => '意见反馈',
            ]);


            return ['code' => 1, 'msg' => '提交成功'];

        } catch (\Exception $e) {
            return ['code' => -1, 'msg' => $e->getMessage()];
        }
    }

}
